drop _all
set more off
clear
clear matrix
clear mata
set mem 4000m
set matsize 7000
set maxvar 10000
set linesize 254
capture log close

capture ereturn clear
capture est store clear
capture matrix drop _all


cd "ADD HERE FOLDER IN WHICH DATA IS CONTAINED"
	

********************************************************************************	
********************************************************************************
*FINAL ANALYSES
********************************************************************************
********************************************************************************
	
	global shortterm_yr_start 1910
	global shortterm_yr_end 1940
	
	global longterm_yr_start 1910
	global longterm_yr_end 1990

use "input\final_data_county_rep.dta", clear
********************************************************************************
********************************************************************************
	*Table 1
********************************************************************************
********************************************************************************

   preserve
   gen lntot_numpat_1920 = lntot_numpat if fdecade==1920
   gen lnind_numpat_1920 = lnind_numpat if fdecade==1920
   gen lnusfirm_numpat_1920 = lnusfirm_numpat if fdecade==1920
   gen lntot_numctd_1920 = lntot_numctd if fdecade==1920
   gen lnind_numctd_1920 = lnind_numctd if fdecade==1920
   gen lnusfirm_numctd_1920 = lnusfirm_numctd if fdecade==1920	
   gen l_tot_avecit_1920 = l_tot_avecit if fdecade==1920
   gen l_ind_avecit_1920 = l_ind_avecit if fdecade==1920
   gen l_usfirm_avecit_1920 = l_usfirm_avecit if fdecade==1920	

   label var lntot_numpat_1920 "   Number Patents"
   label var lnind_numpat_1920 "   Number Patents"
   label var lnusfirm_numpat_1920 "   Number Patents"
   label var lntot_numctd_1920 "   Number Citations"
   label var lnind_numctd_1920 "   Number Citations"
   label var lnusfirm_numctd_1920 "   Number Citations"
   label var l_tot_avecit_1920 "   Average Citations/Patent"
   label var l_ind_avecit_1920 "   Average Citations/Patent"
   label var l_usfirm_avecit_1920 "   Average Citations/Patent"
   
	
	eststo clear
	estpost sum lntot_numpat_1920 lntot_numctd_1920 l_tot_avecit_1920 lnind_numpat_1920 lnind_numctd_1920 l_ind_avecit_1920 lnusfirm_numpat_1920   ///
		lnusfirm_numctd_1920   l_usfirm_avecit_1920 ///
		depsusp33_pos dstr33 pchg_farmval_35_25_win lnpop1920 ue_rate1  rldf3329 num_bank29 manemp3a if  fdecade==1920	
	est store a
	estpost sum lntot_numpat_1920 lntot_numctd_1920 l_tot_avecit_1920 lnind_numpat_1920 lnind_numctd_1920 l_ind_avecit_1920 lnusfirm_numpat_1920   ///
		lnusfirm_numctd_1920   l_usfirm_avecit_1920 ///
		depsusp33_pos dstr33 pchg_farmval_35_25_win lnpop1920 ue_rate1  rldf3329 num_bank29 manemp3a if  fdecade==1920 & depsusp33_pos==1
	est store b
	
	esttab a b using "output\table1.tex", replace ///
	mtitles("\textbf{\emph{All Counties}}" "\textbf{\emph{Counties w/ Suspensions}}") ///
	refcat(lntot_numpat_1920 "\textbf{\emph{1920s Patenting per county (log):}}" lnind_numpat_1920 "\emph{Independent:}" lnusfirm_numpat_1920 "\emph{US Firms:}"  depsusp33_pos "\textbf{\emph{Crisis County-level Variables:} }" lnpop1920 "\textbf{\emph{Misc. County-level Variables:} }" , nolabel) ///
	collabels(\multicolumn{1}{c}{{Mean}} \multicolumn{1}{c}{{Std.Dev.}} \multicolumn{1}{c}{{NumObs}}) ///
	cells("mean(fmt(2)) sd(fmt(2)) count(fmt(0))") label nonumber f noobs alignment(S) booktabs	width(0.5\hsize)
	restore
********************************************************************************
********************************************************************************
	*Table 2 (below)
********************************************************************************
********************************************************************************

********************************************************************************
********************************************************************************
	*Table 3
********************************************************************************
********************************************************************************
	estimates clear
	preserve
	label var lntot_numpat 		"Ln(\# Total Patents+1)"
	label var lnusfirm_numpat 	"Ln(\# Firm Patents+1)"
	label var lnind_numpat 		"Ln(\# Ind. Patents+1)"
		
	reghdfe lnind_numpat depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c1
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnusfirm_numpat depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c2
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end	
	reghdfe lntot_numpat depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c3
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end	

	esttab  t1c1  t1c2  t1c3 using "output\table3.tex", replace label f booktabs style(tex) alignment (c) nofloat ///
			noobs depvars    ///
			hlinechar(`=char(151)') ///			
		varwidth(30) modelwidth (12) collabels(none)  legend  ///
		cells(b(star fmt(%12.3f)) se(par fmt(%12.3f)))  /// 
		keep(*depsusp33_posXafter1929*  ) ///
		stats(stateXtime_fe cnty_fe startyr endyr r2_a N , fmt(0 0 %9.0fc %9.0fc   %9.3fc %9.0fc ) labels("StateXTime FE" "County FE"   "Start Decade" "End Decade" "Adj R-Sq" "Obs") ) ///
		star(* 0.10 ** 0.05 *** 0.01)  
	restore
********************************************************************************
********************************************************************************
	*Table 4
********************************************************************************
********************************************************************************

	estimates clear
	preserve
	label var lnind_numpat 		"Ln(\# Ind. Patents+1)"
	label var change_farmval_35_25_post "High Land Price Drop X After1929"
	label var ue_rate1_top50Xafter1929 "High Unempl. X After1929"
	label var inv_growth_sales_top50Xafter1929 "High Sale Drop X After1929"
	label var depsusp33_posXafter1929 "High Bank Distress X After1929"
	estimates clear
	reghdfe lnind_numpat change_farmval_35_25_post if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c1
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end	
	reghdfe lnind_numpat ue_rate1_top50Xafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c2
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end	
	reghdfe lnind_numpat inv_growth_sales_top50Xafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c3
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end	
	reghdfe lnind_numpat  change_farmval_35_25_post depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c4
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end	
	reghdfe lnind_numpat  ue_rate1_top50Xafter1929 depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c5
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end	
	reghdfe lnind_numpat  inv_growth_sales_top50Xafter1929 depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c6
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end	

	esttab  t1c* using "output\table4.tex", replace label f booktabs style(tex) alignment (c) nofloat ///
			noobs depvars    ///
			hlinechar(`=char(151)') ///			
		varwidth(30) modelwidth (12) collabels(none)  legend  ///
		cells(b(star fmt(%12.3f)) se(par fmt(%12.3f)))  /// 
		keep(change_farmval_35_25_post ue_rate1_top50Xafter1929 inv_growth_sales_top50Xafter1929 depsusp33_posXafter1929) ///
		stats(stateXtime_fe cnty_fe startyr endyr r2_a N , fmt(0 0 %9.0fc %9.0fc   %9.3fc %9.0fc ) labels("StateXTime FE" "County FE"   "Start Decade" "End Decade" "Adj R-Sq" "Obs") ) ///
		star(* 0.10 ** 0.05 *** 0.01)  	
	restore
********************************************************************************
********************************************************************************	
*Table 5 (below)
********************************************************************************
********************************************************************************
	
********************************************************************************
********************************************************************************
	*Table 6
********************************************************************************
********************************************************************************
	estimates clear
 	preserve
	foreach x of varlist lnind_numpat_old lnind_numpat_young  lnind_numpat_exp  lnind_numpat_unexp_mch {
	label var `x' "Ln(\# Ind. Patents+1)"
	}
	label var depsusp33_posXafter1929 "Crisis X After1929"
	
	reghdfe lnind_numpat_exp depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Experienced"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnind_numpat_unexp_mch depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t2
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Inexperienced"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnind_numpat_old depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t3
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Older"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnind_numpat_young depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t4
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Younger"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end

	esttab    t1 t2 t3 t4 using "output\table6.tex", replace label f booktabs style(tex) alignment (c) nofloat ///
		noobs depvars nomtitles ///
		hlinechar(`=char(151)') ///
		mgroups("Ln(\# Independent Patents+1)", pattern(0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})  ) ///
		varwidth(30) modelwidth (12) collabels(none)  legend  ///
		cells(b(star fmt(%12.3f))  se(par fmt(%12.3f)))  /// 
		keep(*depsusp33_posXafter1929*  ) ///
		stats(stateXtime_fe cnty_fe LHS startyr endyr r2_a N , fmt(0 0 0 %9.0fc %9.0fc %9.3fc %9.0fc ) labels("StateXTime FE" "County FE" "Inventor Type" "Start Decade" "End Decade" "Adj R-Sq" "Obs") ) ///
		star(* 0.10 ** 0.05 *** 0.01)  
	
	restore
********************************************************************************
********************************************************************************
	*Table 7
********************************************************************************
********************************************************************************
	estimates clear
	preserve 
	label var lnind_numctd "Ind. \# Cit"
	label var lntot_numctd "Tot. \# Cit"
	label var depsusp33_posXafter1929 "Crisis X After1929"

	reghdfe lnind_numctd depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c1
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe l_ind_avecit depsusp33_posXafter1929   if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c2
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
   	reghdfe lnind_avgctperpat_cpc depsusp33_posXafter1929   if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c3
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe ind_avecit depsusp33_posXafter1929    if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c4
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end

    esttab t1c1  t1c2 t1c3 t1c4  using "output\table7.tex", replace label f booktabs style(tex) alignment (c) nofloat ///
	noobs depvars ///
	hlinechar(`=char(151)') ///
	varwidth(30) modelwidth (12) collabels(none)  legend  ///
	cells(b(star fmt(%12.3f))  se(par fmt(%12.3f)))  /// 
	keep(*depsusp33_posXafter1929*) ///
	stats(stateXtime_fe cnty_fe   startyr endyr r2_a N , fmt(0 0  %9.0fc %9.0fc %9.3fc %9.0fc ) labels("StateXTime FE" "County FE"   "Start Decade" "End Decade" "Adj R-Sq" "Obs") ) ///
	star(* 0.10 ** 0.05 *** 0.01) 
	
	restore
********************************************************************************
********************************************************************************
	*Table 8
********************************************************************************
********************************************************************************
	estimates clear	
	preserve
	foreach x of varlist lnusfirm_new_numpat lnusfirm_old_numpat lnusfirm3pat_1decade_numpat lnusfirm1_2pat_1decade_numpat      {
	label var `x' "Ln(\# Firm Patents+1)"
	}
	label var depsusp33_posXafter1929 "Crisis X After1929"
	
	reghdfe lnusfirm_new_numpat depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "New"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnusfirm_old_numpat depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t2
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Incumbent"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnusfirm1_2pat_1decade_numpat depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t3
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Small Incumbent"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnusfirm3pat_1decade_numpat  depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t4
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Large Incumbent"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end

	esttab    t1 t2 t3 t4 using "output\table8.tex", replace label f booktabs style(tex) alignment (c) nofloat ///
		noobs depvars nomtitles ///
		hlinechar(`=char(151)') ///
		mgroups("Ln(\# Firm Patents+1)", pattern(0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})  ) ///
		varwidth(30) modelwidth (12) collabels(none)  legend  ///
		cells(b(star fmt(%12.3f))  se(par fmt(%12.3f)))  /// 
		keep(*depsusp33_posXafter1929*  ) ///
		stats(stateXtime_fe cnty_fe LHS startyr endyr r2_a N , fmt(0 0 0 %9.0fc %9.0fc %9.3fc %9.0fc ) labels("StateXTime FE" "County FE" "Firm Type" "Start Decade" "End Decade" "Adj R-Sq" "Obs") ) ///
		star(* 0.10 ** 0.05 *** 0.01)  
	
	restore

********************************************************************************
********************************************************************************
	*Table 9
********************************************************************************
********************************************************************************
	estimates clear	
 	preserve
	foreach x of varlist lnusfirm_big_numpat_old  lnusfirm_big_numpat_young  lnusfirm_big_numpat_exp  lnusfirm_big_numpat_unexp_mch  {
	label var `x' "Ln(\# Firm Patents+1)"
	}
	label var depsusp33_posXafter1929 "Crisis X After1929"
	
	reghdfe lnusfirm_big_numpat_exp depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Experienced"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnusfirm_big_numpat_unexp_mch depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t2
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Inexperienced"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnusfirm_big_numpat_old depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t3
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Older"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnusfirm_big_numpat_young depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t4
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Younger"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end

	esttab    t1 t2 t3 t4 using "output\table9.tex", replace label f booktabs style(tex) alignment (c) nofloat ///
		noobs depvars nomtitles ///
		hlinechar(`=char(151)') ///
		mgroups("Ln(\# Firm Patents+1)", pattern(0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})  ) ///
		varwidth(30) modelwidth (12) collabels(none)  legend  ///
		cells(b(star fmt(%12.3f))  se(par fmt(%12.3f)))  /// 
		keep(*depsusp33_posXafter1929*  ) ///
		stats(stateXtime_fe cnty_fe LHS startyr endyr r2_a N , fmt(0 0 0 %9.0fc %9.0fc %9.3fc %9.0fc ) labels("StateXTime FE" "County FE" "Inventor Type" "Start Decade" "End Decade" "Adj R-Sq" "Obs") ) ///
		star(* 0.10 ** 0.05 *** 0.01)  
	
	restore
********************************************************************************
********************************************************************************
	*Table 10 (other do file)
********************************************************************************
********************************************************************************
	
	
********************************************************************************
********************************************************************************
	*Table 11
********************************************************************************
********************************************************************************

	estimates clear	
	preserve
	label var lnind_numpat 		"Ln(\# Ind. Pat.+1)"
	label var lnind_numctd 		"Ln(\# Cit. Ind.+1)"
	label var lnusfirm3pat_1decade_numpat 	"Ln(\# Firm Pat.+1)"
	label var lnusfirm3pat_1decade_numctd 		"Ln(\# Cit. Firm+1)"
	label var depsusp33_posXafter1929 "Crisis X After1929"

	reghdfe lnind_numpat depsusp33_posXafter1929   if fdecade>=$longterm_yr_start & fdecade<=$longterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c1
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $longterm_yr_start
	estadd local endyr $longterm_yr_end	
	reghdfe lnusfirm3pat_1decade_numpat depsusp33_posXafter1929   if fdecade>=$longterm_yr_start & fdecade<=$longterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c2
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"
	estadd local startyr $longterm_yr_start
	estadd local endyr $longterm_yr_end	
	reghdfe lnind_numctd depsusp33_posXafter1929 if fdecade>=$longterm_yr_start & fdecade<=$longterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c3
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"	
	estadd local startyr $longterm_yr_start
	estadd local endyr $longterm_yr_end		
	reghdfe lnusfirm3pat_1decade_numctd depsusp33_posXafter1929 if fdecade>=$longterm_yr_start & fdecade<=$longterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1c4
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "ln()"	
	estadd local startyr $longterm_yr_start
	estadd local endyr $longterm_yr_end		

	esttab  t1c1  t1c2 t1c3  t1c4 using "output\table11.tex", replace label f booktabs style(tex) alignment (c) nofloat ///
		noobs depvars ///
		hlinechar(`=char(151)') ///
		varwidth(30) modelwidth (12) collabels(none)  legend  ///
		cells(b(star fmt(%12.3f))  se(par fmt(%12.3f)))  /// 
		keep(*depsusp33_posXafter1929* ) ///
		stats(stateXtime_fe cnty_fe   startyr endyr r2_a N , fmt(0 0   %9.0fc %9.0fc %9.3fc %9.0fc ) labels("StateXTime FE" "County FE"   "Start Decade" "End Decade" "Adj R-Sq" "Obs") ) ///
		star(* 0.10 ** 0.05 *** 0.01)  
		
	estimates clear
	restore
	
********************************************************************************
********************************************************************************
	*Table 12
********************************************************************************
********************************************************************************
	estimates clear	
	preserve
	foreach x of varlist  lnind_nn lnind_nn_bot lnindteam_numpat   	lnindsolo_numpat   	lnusfirm3pat_1decade_team_numpat   	lnusfirm3pat_1decade_solo_numpat {
	label var `x' "Ln(\# Ind. Patents+1)"
	}
	label var depsusp33_posXafter1929 "Crisis X After1929"	

	reghdfe lnind_nn depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$longterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t1
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "High Fin. Dep."
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnind_nn_bot depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$longterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t2
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Low Fin. Dep."
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnindsolo_numpat  depsusp33_posXafter1929 if fdecade>=$longterm_yr_start & fdecade<=$longterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t3
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Solo Patent"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end
	reghdfe lnindteam_numpat depsusp33_posXafter1929 if fdecade>=$longterm_yr_start & fdecade<=$longterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
	est store t4
	estadd local stateXtime_fe "Y"
	estadd local cnty_fe "Y"
	estadd local LHS "Team Patent"
	estadd local startyr $shortterm_yr_start
	estadd local endyr $shortterm_yr_end


	esttab t1 t2 t3 t4 using "output\table12.tex", replace label f booktabs style(tex) alignment (c) nofloat ///
		noobs depvars nomtitles ///
		hlinechar(`=char(151)') ///
		mgroups("Ln(\# Independent Patents+1)", pattern(0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})  ) ///
		varwidth(30) modelwidth (12) collabels(none)  legend  ///
		cells(b(star fmt(%12.3f))  se(par fmt(%12.3f)))  /// 
		keep(*depsusp33_posXafter1929*  ) ///
		stats(stateXtime_fe cnty_fe LHS startyr endyr r2_a N , fmt(0 0 0 %9.0fc %9.0fc %9.3fc %9.0fc ) labels("StateXTime FE" "County FE" "LHS" "Start Decade" "End Decade" "Adj R-Sq" "Obs") ) ///
		star(* 0.10 ** 0.05 *** 0.01)  
	restore

	
********************************************************************************
********************************************************************************
	*Table 5
********************************************************************************
********************************************************************************
	
		use "input\final_data_tech_year_level_rep.dta", clear
	
		*Aggregate at decade level
		gen fdecade=.
		replace fdecade=1910 if fyear>=1910 & fyear<1920
		replace fdecade=1920 if fyear>=1920 & fyear<1930
		replace fdecade=1930 if fyear>=1930 & fyear<1940
		replace fdecade=1940 if fyear>=1940 & fyear<1950
	
		foreach var of varlist ind_numpat_a ind_numpat_b   ind_numpat_e     ind_numpat_f     ind_numpat_g {
		bys statefips county fdecade: egen x=total(`var')
		replace `var'=x
		drop x
		}
		bys statefips county fdecade: gen n=_n
		keep if n==1
		drop n usfirm_numpat*  ind_numpat
		*Reshape data at industry level
		egen state_county_fips = group(statefips county)
		label var state_county_fips "State-County ID"
		egen statefips_fdecade = group(statefips fdecade)
		label var state_county_fips "State-Decade ID"
		drop if depsusp33_pos==.
		egen statefips_g = group(statefips)
		
		reshape long ind_numpat_ , i(state_county_fips fdecade ) j(industry) string
		
		rename ind_numpat_ ind_num_pat_industry
		replace ind_num_pat_industry = 0 if ind_num_pat_industry==.
		gen ln_ind_num_pat_industry = ln(ind_num_pat_industry + 1)
		
		keep if industry=="a" | industry=="b" |  industry=="e" | industry=="f" | industry=="g"
		
		tab industry		
		egen industry_fdecade = group(industry fdecade)
		egen industry_state_county_fips = group(industry state_county_fips)
		egen industry_statefips_fdecade = group(industry statefips_g fdecade)
	
	
		global shortterm_yr_start 1910
		global shortterm_yr_end 1940


		label var ln_ind_num_pat_industry 	"IndPat"
		label var depsusp33_posXafter1929 "Crisis X After1929"

		reghdfe ln_ind_num_pat_industry depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
		est store t4c1
		estadd local stateXtime_fe "Y"
		estadd local cnty_fe "Y"
		estadd local ind_state_time_fe "N"
		estadd local ind "All"
		estadd local LHS "ln()"
		estadd local startyr $shortterm_yr_start
		estadd local endyr $shortterm_yr_end
		reghdfe ln_ind_num_pat_industry depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end, absorb(state_county_fips industry_statefips_fdecade) vce(cluster state_county_fips)
		est store t4c2
		estadd local stateXtime_fe "Y"
		estadd local cnty_fe "Y"
		estadd local ind_state_time_fe "Y"
		estadd local ind "All"
		estadd local LHS "ln()"
		estadd local startyr $shortterm_yr_start
		estadd local endyr $shortterm_yr_end	
		reghdfe ln_ind_num_pat_industry depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end & industry=="a", absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
		est store t4c3
		estadd local stateXtime_fe "Y"
		estadd local cnty_fe "Y"
		estadd local ind_state_time_fe "N"
		estadd local ind "A"
		estadd local LHS "ln()"
		estadd local startyr $shortterm_yr_start
		estadd local endyr $shortterm_yr_end	
		reghdfe ln_ind_num_pat_industry depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end & industry=="b", absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
		est store t4c4
		estadd local stateXtime_fe "Y"
		estadd local cnty_fe "Y"
		estadd local ind_state_time_fe "N"
		estadd local ind "B"
		estadd local LHS "ln()"
		estadd local startyr $shortterm_yr_start
		estadd local endyr $shortterm_yr_end	
		reghdfe ln_ind_num_pat_industry depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end & industry=="e", absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
		est store t4c5
		estadd local stateXtime_fe "Y"
		estadd local cnty_fe "Y"
		estadd local ind_state_time_fe "N"
		estadd local ind "E"
		estadd local LHS "ln()"
		estadd local startyr $shortterm_yr_start
		estadd local endyr $shortterm_yr_end	
		reghdfe ln_ind_num_pat_industry depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end & industry=="f", absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
		est store t4c6
		estadd local stateXtime_fe "Y"
		estadd local cnty_fe "Y"
		estadd local ind_state_time_fe "N"
		estadd local ind "F"
		estadd local LHS "ln()"
		estadd local startyr $shortterm_yr_start
		estadd local endyr $shortterm_yr_end	
		reghdfe ln_ind_num_pat_industry depsusp33_posXafter1929 if fdecade>=$shortterm_yr_start & fdecade<=$shortterm_yr_end & industry=="g", absorb(state_county_fips statefips_fdecade) vce(cluster state_county_fips)
		est store t4c7
		estadd local stateXtime_fe "Y"
		estadd local cnty_fe "Y"
		estadd local ind_state_time_fe "N"
		estadd local ind "G"
		estadd local LHS "ln()"
		estadd local startyr $shortterm_yr_start
		estadd local endyr $shortterm_yr_end	
				
		esttab  t4c*   using "output\table5.tex", replace label f booktabs style(tex) alignment (c) nofloat ///
			noobs nodepvars nomtitles  ///
			hlinechar(`=char(151)') ///
			mgroups("Ln(\# Independent Patents+1)", pattern(0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})  ) ///
		varwidth(30) modelwidth (12) collabels(none)  legend  ///
		cells(b(star fmt(%12.3f))  se(par fmt(%12.3f)))  /// 
		keep(*depsusp33_posXafter1929*  ) ///
		stats(stateXtime_fe cnty_fe ind_state_time_fe ind   startyr endyr r2_a N , fmt(0 0 0 0   %9.0fc %9.0fc %9.3fc %9.0fc ) labels("StateXTime FE" "County FE" "TechnologyXStateXTime FE" "Technology"   "Start Decade" "End Decade" "Adj R-Sq" "Obs") ) ///
		star(* 0.10 ** 0.05 *** 0.01)  
		
	estimates clear	
		
		
	

 
********************************************************************************
********************************************************************************
	*Figure 1
********************************************************************************
********************************************************************************	
	use "input\final_data_tech_year_level_rep.dta", clear
	keep fyear ind_numpat   usfirm_numpat ind_numpat_a ind_numpat_b   ind_numpat_e  ind_numpat_f ind_numpat_g usfirm_numpat_a  usfirm_numpat_b usfirm_numpat_e usfirm_numpat_g usfirm_numpat_f
	
	foreach var of varlist ind_numpat   usfirm_numpat ind_numpat_a ind_numpat_b   ind_numpat_e  ind_numpat_f ind_numpat_g usfirm_numpat_a  usfirm_numpat_b usfirm_numpat_e usfirm_numpat_g usfirm_numpat_f {
	bys fyear: egen x=total(`var')
	replace `var'=x
	drop x
	replace `var'=`var'/1000
	}
	duplicates drop
	isid fyear

	tsset fyear, yearly
	label var ind_numpat "Independent"
	label var usfirm_numpat "Firms"
	graph twoway line ind_numpat usfirm_numpat fyear, xline(1928.5) name(g1, replace)    ytitle("# Pat.(000s)") xtitle("Year") title("All Technologies") graphregion(color(white))
	graph twoway line ind_numpat_a usfirm_numpat_a fyear, xline(1928.5) name(g2, replace) ytitle("# Pat.(000s)") xtitle("Year")  yscale(range(0 6.500) noextend)  title("CPC A") graphregion(color(white))
	graph twoway line ind_numpat_b usfirm_numpat_b fyear, xline(1928.5) name(g3, replace) ytitle("# Pat.(000s)") xtitle("Year")  title("CPC B") graphregion(color(white))
	graph twoway line ind_numpat_e usfirm_numpat_e fyear, xline(1928.5) name(g4, replace) ytitle("# Pat.(000s)") xtitle("Year")  yscale(range(0 3.200) noextend)  title("CPC E") graphregion(color(white))
	graph twoway line ind_numpat_f usfirm_numpat_f fyear, xline(1928.5) name(g5, replace) ytitle("# Pat.(000s)") xtitle("Year")  yscale(range(0 4.500) noextend) title("CPC F") graphregion(color(white))
	graph twoway line ind_numpat_g usfirm_numpat_g fyear, xline(1928.5) name(g6, replace) ytitle("# Pat.(000s)") xtitle("Year")  yscale(range(0 2.500) noextend) title("CPC G") graphregion(color(white))
	grc1leg g1 g2 g3 g4 g5 g6,  legendfrom(g1) graphregion(color(white))
	graph export "output\figure1.pdf", replace

	
	
********************************************************************************
********************************************************************************
	*Figure 2
********************************************************************************
********************************************************************************
	use "input\final_data_year_level_rep.dta", clear
	preserve
		keep if fyear>=1910 & fyear<1950 
		

		*Reshape the data in a five-year group. 
		gen five_yr=.
		replace five_yr=1910 if fyear>=1910 & fyear<1915
		replace five_yr=1915 if fyear>=1915 & fyear<1920
		replace five_yr=1920 if fyear>=1920 & fyear<1925
		replace five_yr=1925 if fyear>=1925 & fyear<1930
		replace five_yr=1930 if fyear>=1930 & fyear<1935
		replace five_yr=1935 if fyear>=1935 & fyear<1940
		replace five_yr=1940 if fyear>=1940 & fyear<1945
		replace five_yr=1945 if fyear>=1945 & fyear<1950

		foreach var of varlist ind_numpat {
		cap drop ln`var'
		bys state_county_fips five_yr: egen x=total(`var')
		replace `var'=x
		drop x
		gen ln`var'=ln(`var'+1)
		}
		
		gen after1929  = five_yr > 1929
		egen statefips_five_yr = group(statefips five_yr)	
		
		tab five_yr, gen(five_yr)
		foreach num of numlist 1(1)8 {
		gen int_five_yr`num'_anyclosure=five_yr`num'*depsusp33_pos	

		}

		bys state_county_fips five_yr: gen n=_n
		keep if n==1
		drop n
		

		
		label var int_five_yr1_anyclosure "1910-14"
		label var int_five_yr2_anyclosure "1915-19"
		label var int_five_yr3_anyclosure "1920-24"
		label var int_five_yr4_anyclosure "1925-29"
		label var int_five_yr5_anyclosure "1930-34"
		label var int_five_yr6_anyclosure "1935-39"
		label var int_five_yr7_anyclosure "1940-44"
		label var int_five_yr8_anyclosure "1945-49"
		
		
		reghdfe lnind_numpat  /// 
			 int_five_yr1_anyclosure int_five_yr2_anyclosure int_five_yr3_anyclosure o.int_five_yr4_anyclosure int_five_yr5_anyclosure /// 
			int_five_yr6_anyclosure int_five_yr7_anyclosure int_five_yr8_anyclosure , absorb(state_county_fips statefips_five_yr) vce(cluster state_county_fips)
		estimates store fig_5yr
		
		coefplot fig_5yr, xline(4 ,lcolor(red) lpattern(dash)) vertical keep(*int_five_*) recast(connected) xlabel(, labsize(small)) nooffset /// 
				ytitle("Diff-in-Diff Coefficient {&beta}") xtitle("") title("", size(samll)) graphregion(color(white)) ylabel(, labsize(small) nogrid) yline(0, lcolor(black)) msize(small) grid(none) omitted
		
		
		graph export "output\figure2.pdf", as(pdf) replace	
		estimates clear	

	restore
	
	
********************************************************************************
********************************************************************************
	*Figure 3
********************************************************************************
********************************************************************************

	preserve
		keep if fyear>=1900 & fyear<1999

		
		gen ten_yr=.
		replace ten_yr=1900 if fyear>=1899 & fyear<1909
		replace ten_yr=1910 if fyear>=1909 & fyear<1919			
		replace ten_yr=1920 if fyear>=1919 & fyear<1929
		replace ten_yr=1930 if fyear>=1929 & fyear<1939
		replace ten_yr=1940 if fyear>=1939 & fyear<1949
		replace ten_yr=1950 if fyear>=1949 & fyear<1959
		replace ten_yr=1960 if fyear>=1959 & fyear<1969
		replace ten_yr=1970 if fyear>=1969 & fyear<1979
		replace ten_yr=1980 if fyear>=1979 & fyear<1989
		replace ten_yr=1990 if fyear>=1989 & fyear<1999

		
		foreach var of varlist ind_numpat  {
		cap drop ln`var'
		bys state_county_fips ten_yr: egen x=total(`var')
		replace `var'=x
		drop x
		gen ln`var'=ln(`var'+1)
		}
		
		egen statefips_ten_yr = group(statefips ten_yr)	

		tab ten_yr, gen(ten_yr)
		
		foreach num of numlist 1(1)10 {
		gen int_ten_yr`num'_anyclosure=ten_yr`num'*depsusp33_pos
		
		}
		
		*Collapse data
		bys state_county_fips ten_yr: gen n=_n
		keep if n==1
		drop n
				
		label var int_ten_yr1_anyclosure 1900s
		label var int_ten_yr2_anyclosure 1910s
		label var int_ten_yr3_anyclosure 1920s
		label var int_ten_yr4_anyclosure 1930s
		label var int_ten_yr5_anyclosure 1940s
		label var int_ten_yr6_anyclosure 1950s
		label var int_ten_yr7_anyclosure 1960s
		label var int_ten_yr8_anyclosure 1970s
		label var int_ten_yr9_anyclosure 1980s
		label var int_ten_yr10_anyclosure 1990s
		
		
		reghdfe lnind_numpat  /// 
			int_ten_yr1_anyclosure int_ten_yr2_anyclosure  o.int_ten_yr3_anyclosure  int_ten_yr4_anyclosure  int_ten_yr5_anyclosure int_ten_yr6_anyclosure int_ten_yr7_anyclosure int_ten_yr8_anyclosure /// 
			int_ten_yr9_anyclosure int_ten_yr10_anyclosure  if ten_yr>=1900, absorb(state_county_fips statefips_ten_yr) vce(cluster state_county_fips)
		estimates store fig_long
		
		coefplot fig_long, xline(3 ,lcolor(red) lpattern(dash)) vertical keep(*int_ten_*) recast(connected) xlabel(, labsize(small)) nooffset /// 
				ytitle("Diff-in-Diff Coefficient {&beta}") xtitle("") title("", size(samll)) graphregion(color(white)) ylabel(, labsize(small) nogrid) yline(0, lcolor(black)) msize(small) grid(none) omitted

				
		graph export "output\figure3.pdf", replace	
		estimates clear	
		restore
		
